﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MCDirectHost.Classes;
using System.Threading;

namespace MCDirectHost
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		AsynchronousSocketListener async = new AsynchronousSocketListener(11000);

		public MainWindow()
		{
			InitializeComponent();

			//async.ClientSignOn += new SignOnHandler(async_ClientSignOn);
			//async.HostStart += new HostStartHandler(async_HostStart);

			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
			AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
		}

		void CurrentDomain_ProcessExit(object sender, EventArgs e)
		{
			async.StopHost();
		}

		void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			MessageBox.Show((e.ExceptionObject as Exception).Message);
		}

		private void button1_Click(object sender, RoutedEventArgs e)
		{
			//Thread t = new Thread(new ThreadStart(async.StartListening));
			//t.Start();
		}

		void async_HostStart(object sender, AsyncSocEventArgs e)
		{
			
		}

		void async_ClientSignOn(object sender, AsyncSocEventArgs e)
		{
			
		}

		private void button2_Click(object sender, RoutedEventArgs e)
		{
			//async.StopHost();
		}
	}
}
